<template>
	<!-- 设施信息 -->
	<view>
		<view class="title">
			<view class="left">住户信息</view>
			<view class="right">
				<text class="add" @click="goScan">
					+
				</text>
				<text @click="onAdd" style="color: #5094FF;">新增住户</text>
			</view>
		</view>
		<view class="info">
			<view v-if="residentList.length !== 0">
				<view class="info-item" @click="goDetail(item)" v-for="item in residentList" :key="item.id">
					<view>
						<view class="info-wrap">姓名：{{item['姓名']}}</view>
						<view class="info-wrap">电话：{{item['手机号'] | phoneHide(personType)}}</view>
						<view class="info-wrap">证件编号：{{item['证件编号'] | idNumHide(personType)}}</view>
						<view class="info-wrap">与户主关系：{{residentTypeObj[item['户主关系']]}}</view>
					</view>
					<view class="arrow"></view>
					<view class="delete" @click.stop="onDelete(item.id)">删除</view>
				</view> 
			</view>
			<view v-else class="empty">暂无住户</view>
		</view>
	</view>
</template>

<script>
	import { mapState } from 'vuex'
	export default {
		props: ['residentList', 'originId'],
		data() {
			return {
				residentTypeObj: this.$type.residentTypeObj
			}
		},
		computed: {
			...mapState(['personType'])
		},
		methods: {
			onAdd() {
				if(this.personType == 1 && uni.getStorageSync('gridInfo').户主关系 !== 1) {
					uni.showToast({
						title: '没有添加权限',
						icon: 'none'
					})
					return
				}
				this.$emit('add')
			},
			onDelete(id) {
				if(this.personType == 1 && uni.getStorageSync('gridInfo').户主关系 !== 1) {
					uni.showToast({
						title: '没有删除权限',
						icon: 'none'
					})
					return
				}
				this.$emit('delete', id)
			},
			goDetail(item) {
				if(item.手机号 !== uni.getStorageSync('gridInfo').手机号 && this.personType == 1 && uni.getStorageSync('gridInfo').户主关系 !== 1) {
					uni.showToast({
						title: '没有权限查看该住户信息',
						icon: 'none'
					})
					return
				}
				uni.navigateTo({
					url: '/fireGridCheck/addResident/addResident?residentId=' + item.id + '&originId=' + this.originId
				})
			}
		},
		filters: {
			phoneHide(val,personType) {
				if(personType == 1) {
					return val.slice(0,4) + '****'+ val.slice(8)
				}
				return val
			},
			idNumHide(val,personType) {
				if(personType == 1) {
					return val.slice(0,8) + '******' + val.slice(14)
				}
				return val
			}
		}
	}
</script>

<style lang="scss" scoped>
.title {
	padding: 0 14rpx;
	display: flex;
	align-items: center;
	justify-content: space-between;
	margin-bottom: 40rpx;
	font-size: 34rpx;
	.left {
		font-size: 32rpx;
		&:before {
			content: '';
			position: absolute;
			top: 24rpx;
			left: 24rpx;
			width: 6rpx;
			height: 34rpx;
			background-color: #5094FF;
		}
	}
	.add {
		font-size: 32rpx;
		font-weight: bold;
		color: #5094FF;
		margin-right: 10rpx;
	}
}
.info {
	margin-left: 16rpx;
	font-size: 28rpx;
	// display: flex;
	// justify-content: center;
	// align-items: center;
	.empty {
		// width: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
		height: 174rpx;
		color: #999;
	}
	.info-item {
		position: relative;
		margin-bottom: 10rpx;
		box-shadow: 0px 1px 6rpx 0px #EEEEEE;
		// border-bottom: 2rpx solid #eee;
		.info-title {
			margin-bottom: 20rpx;
		}
		.info-wrap {
			line-height: 50rpx;
		}
		.arrow {
			position: absolute;
			top: 90rpx;
			right: 40rpx;
			width: 20rpx;
			height: 20rpx;
			border-top: 2rpx solid #333;
			border-right: 2rpx solid #333;
			transform: rotate(45deg);
		}
		.delete {
			position: absolute;
			right: 20rpx;
			bottom: 10rpx;
			text-align: center;
			line-height: 40rpx;
			width: 80rpx;
			height: 40rpx;
			font-size: 24rpx;
			color: #E57544;
			border: 2rpx solid #E57544;
		}
	}
}
</style>
